import { createI18n } from 'vue-i18n'

let locale = 'en'

const GlobyStory = window.sessionStorage.getItem('GlobyStory') || '{}'

try {
  const { language } = JSON.parse(GlobyStory)
  language && (locale = language)
} catch (error) {
  throw new Error('GlobyStory is not a valid JSON')
}

const i18n = createI18n({
  legacy: false,
  locale,
  fallbackLocale: 'zhCn',
  missingWarn: false,
  fallbackWarn: false,
  messages: {
    en: {
      头部: 'Header',
      中文: 'zhCn',
      英文: 'en'
    },
    zhCn: {
      //   头部: '头部',
      //   中文: '中文',
      //   英文: '英文'
    }
  }
})

export default i18n
export { locale }
